This page last changed on Jan 09, 2008 by tkatz.
eDocs Home > BEA AquaLogic Data Services Platform 3.0 Documentation > Data Services Developer's Guide
How To Cast Using a Custom XQuery Function
This topic describes how to write a custom XQuery function to cast between elements of different data types in an update map.
Example
An example of a custom XQuery cast function is one that casts from integer to string. Suppose the logical data service's return type uses xsd:integer for the TELEPHONE_NUMBER element, while the underlying data source uses xsd:string.
Mapping from Integer to String

The mapping between the two TELEPHONE_NUMBER elements is initially disabled. The value from the return type is something like 4155551212, which can easily be converted between xsd:integer and xsd:string. Check the type casting chart in the XQuery 1.0 specification to make sure the cast you want to perform is allowed.
 | When you test the cast function, you also need to perform the opposite cast (in this case, xsd:string to xsd:integer). |
To write a custom XQuery cast function:
- Click the Source tab.
- Write an XQuery function that takes an argument of the data type you are casting from and returns a value of the data type you are casting to, for example:
declare function tns:intToString($theint as xs:integer) as xs:string {
xs:string($theint)
};
Assign your function to an XML namespace your logical data service uses. Be sure both the parameter and return type are valid XML Schema data types. Then, write a statement that performs the cast.
- In the Update Map tab, click the element in the data source on the left.
At this point, the element is disabled: . Its value is taken from the return type, so its XQuery expression looks something like this:
fn-bea:value($CUSTOMER/TELEPHONE_NUMBER)
Remember that the value from the return type is an xs:integer.
- Add your new cast function, using the existing expression as its argument, for example:
tns:intToString(fn-bea:value($CUSTOMER/TELEPHONE_NUMBER))
At this point, the update map should be completely enabled.
- If the disabled icon on the element does not disappear immediately, click another element in the update map.
- Test the update map cast to make sure it works as you expect.
See Also
Concepts
How To
Other Resources
Contact BEA | Feedback | Privacy | (c) 2008 BEA Systems
|